/*
窗口帮助类
@auth 邓柳江
*/
Ext.Loader.setConfig({enabled: true});
Ext.define('common.windowHelper', {
	requires:[
         'Ext.window.MessageBox',
         'Ext.tip.*'
    ],

    statics: {
		/**
		 * 新增tabs页
		 * @param title
		 * @param src
		 */
		addTabs : function (tabId, tabText, tabSrc, paramsObj) {
			//获得tab容器tabpanel
            var tabPanel=Ext.getCmp('sysTabPanel');
            //获得被选中的tab组建对象
            var tab = tabPanel.getComponent(tabId);
            
            //如果此tab还未被创建，则向tab容器添加一个tab
            if(tab){
            	tabPanel.remove(tab);
            }
            
            var loaderConfig;
        	if (paramsObj) {
        		loaderConfig = {
    				url: tabSrc,
                    contentType: 'html',
                    autoLoad: true,
                    params: paramsObj,
                    scripts: true,
                    loadMask: true,
                    callback : function(loader, active, response){
				        var responseText = response.responseText;
				        if(responseText.match("{success:false, data:'.*'}")) {
				        	var respData = Ext.decode(responseText);
				        	if(!respData.success){
				        		common.windowHelper.getActiveTab().close();
                    			common.msgHelper.msg("获取数据失败",respData.data);
                    		}
				        }
				    }
        		}
        	} else {
        		loaderConfig = {
    				url: tabSrc,
                    contentType: 'html',
    				loadMask: true,
    				scripts: true,
                    autoLoad: true,
                    callback : function(loader, active, response){
				        var responseText = response.responseText;
				        if(responseText.indexOf("{success:false, data:") == 0) {
				        	var respData = Ext.decode(responseText);
				        	if(!respData.success){
				        		common.windowHelper.getActiveTab().close();
                    			common.msgHelper.msg("获取数据失败",respData.data);
                    		}
				        }
				    }
        		}
        	}
            tab = tabPanel.add({
                id:tabId,
                title:tabText,
                closable:true,
                autoWidth:true,
                autoHeight:true,
                autoScroll:true,
                active:true,//为了兼容IE9
                fit:true,
                //html: tabSrc
                loader: loaderConfig
                //html:'<p>id:'+selectedItem.data.id+'</p>'
            }).show();

            //将tab设置为当前可见可操作tab
            tabPanel.setActiveTab(tab);//其实这步是多余的，但是在IE9下，没这步就显示不正常。

            //异步加载js并执行，参数为要加载的JS文件的URL，这个JS包含tab内容区内容的构建程序。
            //loadJS(selectedItem.data.hrefTarget);//此函数为自定义函数，已在上面定义。
		},
		
		/**
		 * 关闭标签
		 */
		
		closeTab : function (tabId){
			//获得tab容器tabpanel
            var tabPanel=Ext.getCmp('sysTabPanel');
            //获得被选中的tab组建对象
            var tab = tabPanel.getComponent(tabId);
            
            //如果此tab还未被创建，则向tab容器添加一个tab
            if(tab){
            	tabPanel.remove(tab);
            }
		},
		
		/**
		 * 获取当前选中tabs页
		 */
		getActiveTab : function () {
			return Ext.getCmp('sysTabPanel').getActiveTab();
		},
		
		/**
		 * 创建新的模态窗口
		 * @param config 
		 */
		createWindow : function(windowConfig) {
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				autoScroll : true,
				closeAction : 'destroy',
				layout: 'fit',
				//cls : "x-btn-text-icon",
				id : windowConfig.id,
				title : windowConfig.title,
				width : windowConfig.width,
				height : windowConfig.height,
				minWidth: 300,
		        minHeight: 200,
				//resizable : windowConfig.resizable,
				//listeners : windowConfig.listeners,
		        active:true,//为了兼容IE9
                fit:true,
		        loader: {
    				url: windowConfig.url,
                    contentType: 'html',
                    autoLoad: true,
                    params: windowConfig.paramsObj,
                    scripts: true,
                    loadMask: true,
                    callback:windowConfig.callback
        		},
				buttons: windowConfig.buttons
			});
			win.show();
			return win;
		},
		/**
		 * 创建产品选择窗口
		 * @param config 
		 */
		createProductTreeWindow : function() {
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				closeAction : 'destroy',
				layout: 'fit',
				id : 'common-productTree-Win',
				title : '选择产品信息',
				width  : 720,
   				height : 360,
				minWidth: 300,
		        minHeight: 200,
		        active:true,//为了兼容IE9
                fit:true,
		        loader: {
		        	url: '/crm/product/commonTree.do',
                   	contentType: 'html',
                   	autoLoad: true,
                  	scripts: true,
                   	loadMask: true
       			}
			});
			win.show();
		},
		/**
		 * 创建修改密码窗口
		 */
		showChangePwdWin : function() {
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				autoScroll : true,
				closeAction : 'destroy',
				layout: 'fit',
				id : 'common-editePwd-Win',
				title : '修改密码',
				width  : 310,
   				height : 160,
   				active:true,//为了兼容IE9
                fit:true,
		        loader: {
		        	url: '/crm/framework/webappmain/changePwdPag.do',
                   	contentType: 'html',
                   	autoLoad: true,
                  	scripts: true,
                   	loadMask: true
       			}
			});
			win.show();
		},
		/**
		 * 创建部门选择窗口
		 * @param config 
		 */
		createOrgTreeWindow : function() {
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				autoScroll : true,
				closeAction : 'destroy',
				layout: 'fit',
				id : 'common-orgTree-Win',
				title : '选择部门信息',
				width  : 700,
   				height : 340,
				minWidth: 300,
		        minHeight: 200,
		        active:true,//为了兼容IE9
                fit:true,
		        loader: {
		        	url: '/crm/framework/org/commonTree.do',
                   	contentType: 'html',
                   	autoLoad: true,
                  	scripts: true,
                   	loadMask: true
       			}
			});
			win.show();
		},
		
		/**
		 * 创建岗位选择窗口
		 * @param config 
		 */
		createPostTreeWindow : function() {
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				autoScroll : true,
				closeAction : 'destroy',
				layout: 'fit',
				id : 'common-postTree-Win',
				title : '选择岗位信息',
				width  : 700,
   				height : 340,
				minWidth: 300,
		        minHeight: 200,
		        active:true,//为了兼容IE9
                fit:true,
		        loader: {
		        	url: '/crm/framework/post/commonTree.do',
                   	contentType: 'html',
                   	autoLoad: true,
                  	scripts: true,
                   	loadMask: true
       			}
			});
			win.show();
		},
		/**
		 * 创建邮件模板选择窗口
		 * @param config 
		 */
		createMailMoudleWindow : function() {
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				autoScroll : true,
				closeAction : 'destroy',
				layout: 'fit',
				id : 'common-MailList-Win',
				title : '邮件模板信息',
				width  : 700,
   				height : 600,
				minWidth: 300,
		        minHeight: 200,
		        active:true,//为了兼容IE9
                fit:true,
		        loader: {
		        	url: '/crm/remind/commonMailList.do',
                   	contentType: 'html',
                   	autoLoad: true,
                  	scripts: true,
                   	loadMask: true
       			}
			});
			win.show();
		},
		/**
		 * 创建人员选择窗口
		 */
		createChoosePersonWindow : function (){
			var win = Ext.create('Ext.Window', {
				closable : true,
				plain:true,
				modal : true,
				autoScroll : true,
				closeAction : 'destroy',
				layout: 'fit',
				id : 'crm-choosePerson',
				title : '选择用户',
				width  : 510,
				height : 500,
				minWidth: 350,
		        minHeight: 300,
		        active:true,
		        loader: {
					url: '/crm/order_product/choosePersonJsp.do',
		           	contentType: 'html',
		           	autoLoad: true,
		           	scripts: true,
		           	loadMask: true
				}
			});
				win.show();
		}
		
		
		
		
		
		
		

	}
});
